/**
 * @Project Name:blog-authentication-server
 * @Package Name:cn.hoofungson.blog.authentication.server.enhancer
 * @Since JDK 1.8
 */

package cn.hoofungson.blog.authentication.server.enhancer;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description: TokenEnhancer
 * @Author 胡松 hoofungson@163.com
 * @Date 2020-01-30 19:45
 * @Version V1.0
 */
public class JwtTokenEnhancer implements TokenEnhancer {

    /**
     * Provides an opportunity for customization of an access token (e.g. through its additional information map) during
     * the process of creating a new token for use by a client.
     *
     * @param accessToken    the current access token with its expiration and refresh token
     * @param authentication the current authentication including client and user details
     * @return a new token enhanced with additional information
     */
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("code", 20000);
        map.put("message", "登录成功！！");
        DefaultOAuth2AccessToken defaultOAuth2AccessToken = (DefaultOAuth2AccessToken)accessToken;
        defaultOAuth2AccessToken.setAdditionalInformation(map);
        return defaultOAuth2AccessToken;
    }
}
